/**
 *  @file SSLServerSocket.h
 */
#ifndef _SSLSERVERSOCKET_H_
#define _SSLSERVERSOCKET_H_

#include "../Socket.h"
#include "SSLContext.h"

namespace cppflib
{

namespace net
{

namespace ssl
{

class SSLSocket;

/**
 *  Server SSL Socket
 */
class _DLLAPI SSLServerSocket : public Socket
{
private:
    SSLContext *pSSLCtx;
    ISSLPeerCertCallback *pPeerCertCallback;

private:
    SSLServerSocket(void);
    SSLServerSocket(SSLContext *pSSLCtx, ISSLPeerCertCallback *pPeerCertCb);

private:
    virtual bool Create(const CFString &socketAddress, u16_t socketPort, Socket::SocketType socketType);
    virtual bool Connect(const CFString &hostAddress, u16_t hostPort);
    virtual bool Connect(const CFString &hostAddress, u16_t hostPort, int timeout);
    virtual bool Accept(Socket &connectedSocket);
    virtual int ReceiveFrom(u8_t * pBuf, int bufLen, int nFlags, CFString &peerAddress, u16_t &peerPort);
    virtual int ReceiveFromTimeout(int timeout, u8_t * pBuf, int bufLen, int nFlags, CFString &peerAddress, u16_t &peerPort);
    virtual int SendTo(const u8_t * pBuf, int bufLen, int nFlags, const CFString &peerAddress, u16_t peerPort);

public:
    virtual ~SSLServerSocket(void);

    bool Create(const CFString &socketAddress, u16_t socketPort);
    SSLSocket *Accept(ISSLPeerCertCallback *pPeerCertCb);
    virtual Socket *Accept();

    friend class SSLContext;
};

} // end of namespace ssl

} // end of namespace net

} // end of namespace cppflib

#endif
